/*
   Copyright (c) 2011, 2015 Mizar Tools Contributors (mizartools.org)

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/
/*  Contributors :
 *	2011-02-05 Marco Riccardi - initial implementation
 *  2011-03-25 Marco Riccardi - implementation of visitor pattern
 *  2011-09-13 Marco Riccardi - added Sethood property in MML 4.165
 *							  - changed Property -> AbstractProperty
 *  2015-01-11 Marco Riccardi - added Asymmetry property in MML 5.22
 */
package org.mizartools.system.xml;

import java.util.LinkedList;

import org.mizartools.system.ElementParseException;
import org.mizartools.system.INode;
import org.mizartools.utility.xml.XMLElement;

public abstract class AbstractProperty implements INode {

    private enum MySubclass { UnexpectedProp, Symmetry, Reflexivity, Irreflexivity, Associativity, Transitivity, Commutativity, Connectedness, Antisymmetry, Idempotence, Involutiveness, Projectivity, Abstractness, Sethood, Asymmetry}

    public static boolean isProperty(String className){
        boolean found = false;
        for (MySubclass mySubclass :MySubclass.values()){
            if (mySubclass.name().equals(className)){
                found = true;
                break;
            }
        }
        return found;
    }

    public String getPropertyName(){
        if (this instanceof UnexpectedProp) {
            return "UnexpectedProp";
        } else 
        if (this instanceof Symmetry) {
            return "Symmetry";
        } else 
        if (this instanceof Reflexivity) {
            return "Reflexivity";
        } else 
        if (this instanceof Irreflexivity) {
            return "Irreflexivity";
        } else 
        if (this instanceof Associativity) {
            return "Associativity";
        } else 
        if (this instanceof Transitivity) {
            return "Transitivity";
        } else 
        if (this instanceof Commutativity) {
            return "Commutativity";
        } else 
        if (this instanceof Connectedness) {
            return "Connectedness";
        } else 
        if (this instanceof Antisymmetry) {
            return "Antisymmetry";
        } else 
        if (this instanceof Idempotence) {
            return "Idempotence";
        } else 
        if (this instanceof Involutiveness) {
            return "Involutiveness";
        } else 
        if (this instanceof Projectivity) {
            return "Projectivity";
        } else 
        if (this instanceof Abstractness) {
            return "Abstractness";
        } else 
        if (this instanceof Sethood) {
            return "Sethood";
        } else 
        if (this instanceof Asymmetry) {
            return "Asymmetry";
        } else 
        return "";
    }
    
    public static AbstractProperty newInstance(INode parentNode, LinkedList<XMLElement> xmlElementList) throws ElementParseException {
        XMLElement xmlElement = xmlElementList.peek();
        if (!isProperty(xmlElement.getName())){
            throw new ElementParseException(ElementParseException.NOT_VALID_ELEMENT, "XMLElement is a " + xmlElement.getName() + " not a subclass of AbstractProperty", xmlElementList);
        }
        MySubclass mySubclass = MySubclass.valueOf(xmlElement.getName());
        switch (mySubclass) {
        case UnexpectedProp: return UnexpectedProp.newInstance(parentNode, xmlElementList);
        case Symmetry: return Symmetry.newInstance(parentNode, xmlElementList);
        case Reflexivity: return Reflexivity.newInstance(parentNode, xmlElementList);
        case Irreflexivity: return Irreflexivity.newInstance(parentNode, xmlElementList);
        case Associativity: return Associativity.newInstance(parentNode, xmlElementList);
        case Transitivity: return Transitivity.newInstance(parentNode, xmlElementList);
        case Commutativity: return Commutativity.newInstance(parentNode, xmlElementList);
        case Connectedness: return Connectedness.newInstance(parentNode, xmlElementList);
        case Antisymmetry: return Antisymmetry.newInstance(parentNode, xmlElementList);
        case Idempotence: return Idempotence.newInstance(parentNode, xmlElementList);
        case Involutiveness: return Involutiveness.newInstance(parentNode, xmlElementList);
        case Projectivity: return Projectivity.newInstance(parentNode, xmlElementList);
        case Abstractness: return Abstractness.newInstance(parentNode, xmlElementList);
        case Sethood: return Sethood.newInstance(parentNode, xmlElementList);
        case Asymmetry: return Asymmetry.newInstance(parentNode, xmlElementList);
        default: throw new ElementParseException(ElementParseException.NOT_VALID_ELEMENT, "XMLElement is a " + xmlElement.getName() + " not a subclass of AbstractProperty", xmlElementList);
        }
    }

        public LinkedList<XMLElement> getXMLElementList() {
            if (this instanceof UnexpectedProp) {
                return ((UnexpectedProp) this).getXMLElementList();
            } else 
            if (this instanceof Symmetry) {
                return ((Symmetry) this).getXMLElementList();
            } else 
            if (this instanceof Reflexivity) {
                return ((Reflexivity) this).getXMLElementList();
            } else 
            if (this instanceof Irreflexivity) {
                return ((Irreflexivity) this).getXMLElementList();
            } else 
            if (this instanceof Associativity) {
                return ((Associativity) this).getXMLElementList();
            } else 
            if (this instanceof Transitivity) {
                return ((Transitivity) this).getXMLElementList();
            } else 
            if (this instanceof Commutativity) {
                return ((Commutativity) this).getXMLElementList();
            } else 
            if (this instanceof Connectedness) {
                return ((Connectedness) this).getXMLElementList();
            } else 
            if (this instanceof Antisymmetry) {
                return ((Antisymmetry) this).getXMLElementList();
            } else 
            if (this instanceof Idempotence) {
                return ((Idempotence) this).getXMLElementList();
            } else 
            if (this instanceof Involutiveness) {
                return ((Involutiveness) this).getXMLElementList();
            } else 
            if (this instanceof Projectivity) {
                return ((Projectivity) this).getXMLElementList();
            } else 
            if (this instanceof Abstractness) {
                return ((Abstractness) this).getXMLElementList();
            } else 
            if (this instanceof Sethood) {
                return ((Sethood) this).getXMLElementList();
            } else 
            if (this instanceof Asymmetry) {
                return ((Asymmetry) this).getXMLElementList();
            } else 
            return new LinkedList<XMLElement>();
        }
}
